package com.xzz.cloud.provider.controller;

import com.xzz.cloud.entity.CommonResult;
import com.xzz.cloud.entity.Payment;
import com.xzz.cloud.provider.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author: hhz
 * @createDate: 2021-4-2
 */
@RestController
@Slf4j
public class PaymentController {
    @Resource
    private PaymentService paymentService;
    @Value("${server.port}")
    private String serverPort;
    @GetMapping("/payment/hystrix/ok/{id}")
    public String paymentInfo_ok(@PathVariable(value = "id") Integer id){
        String result=paymentService.paymentInfo_ok(id);
        log.info("*******result="+result);
        return result;
    }

    @GetMapping("/payment/hystrix/timeout/{id}")
    public String paymentInfo_timeout(@PathVariable(value = "id") Integer id){
        String result=paymentService.paymentInfo_timeout(id);
        log.info("*******result="+result);
        return result;
    }

//    //===服务熔断
//    @GetMapping("/payment/circuit/{id}")
//    public String paymentCircuitBreaker(@PathVariable("id") Integer id){
//        String result = paymentService.paymentCircuitBreaker(id);
//        log.info("*******result:"+result);
//        return result;
//    }

    //通过id进行查询
    @GetMapping("/payment/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id) {
        Payment payment = paymentService.getPaymentById(id);
        if (payment != null) {
            return new CommonResult(200, "查询成功serverPort：" + serverPort, payment);
        } else {
            return new CommonResult(444, "没有对应记录，serverPort：" + serverPort + "查询ID：" + id, null);
        }
    }
}
